package org.idream.pomelo
{
	import flash.events.NetStatusEvent;
	import flash.net.SharedObject;
	import flash.system.Security;
	
	public class LocalData
	{
		 
		
		private var so:SharedObject;
		
		public function LocalData(param1:String)
		{
			super();
			so = SharedObject.getLocal(param1);
		}
		
		public function writeSo(param1:Object) : void
		{
			so.data.obj = param1;
			flushHandler();
		}
		
		private function flushHandler():void
		{
			try
			{
				var status:String = so.flush(1048576);

				if (status == "pending")
				{
					so.addEventListener("netStatus", onStatus);
				}
				// No action needed if status is "flushed"
			}
			catch (error:Error)
			{
				Security.showSettings("localStorage");
			}
		}
		
		private function onStatus(param1:NetStatusEvent) : void
		{
			if(param1.info.code != "SharedObject.Flush.Success")
			{
				if(param1.info.code == "SharedObject.Flush.Failed")
				{
				}
			}
			so.removeEventListener("netStatus",onStatus);
		}
		
		public function readSo() : Object
		{
			return so.data.obj;
		}
		
		public function delSo() : void
		{
			so.data.obj = null;
		}
	}
}
